import 'package:flutter/material.dart';
import 'package:duo_zui/page/news.dart';
import 'package:duo_zui/page/AppListPage.dart';
import 'package:duo_zui/router.dart';
import 'package:duo_zui/widget/search_text_field_widget.dart';
import 'package:duo_zui/page/home_app_bar.dart' as myapp;


class TabbedAppBarMain extends StatelessWidget {
  var titleList = ['好文推荐','APP精选'];

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      theme: ThemeData(
        primaryColor: Colors.white,
      ),
      home: new DefaultTabController(
        length: titleList.length,
        child: NestedScrollView(
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            // These are the slivers that show up in the "outer" scroll view.
            return <Widget>[
              SliverOverlapAbsorber(
                // This widget takes the overlapping behavior of the SliverAppBar,
                // and redirects it to the SliverOverlapInjector below. If it is
                // missing, then it is possible for the nested "inner" scroll view
                // below to end up under the SliverAppBar even when the inner
                // scroll view thinks it has not been scrolled.
                // This is not necessary if the "headerSliverBuilder" only builds
                // widgets that do not overlap the next sliver.
                handle: NestedScrollView.sliverOverlapAbsorberHandleFor(context),
                sliver: myapp.SliverAppBar(
                  pinned: true,
                  expandedHeight: 135.0,
                  primary: true,
                  titleSpacing: 0.0,
                  backgroundColor: Colors.white,
                  flexibleSpace: FlexibleSpaceBar(
                    collapseMode: CollapseMode.pin,
                    background: Container(
                      color: Colors.green,
                      child: Row(
                         children: <Widget>[
                           Expanded(
                             child:
                               SearchTextFieldWidget(
                                 hintText: '与你相遇 三生有幸',
                                 margin: const EdgeInsets.only(left: 15.0, top: 12.0, right: 7.0),
                                 onTab: () {
                                   MyRouter.push(context, MyRouter.searchPage, '与你相遇 三生有幸');
                                 },
                               ),
                           ),
                           GestureDetector(
                             child: Padding(
                               padding: EdgeInsets.fromLTRB(2.0, 16.0 , 8.0, 0),
                               child: Icon(
                                 Icons.account_circle,
                                 color: Colors.white,
                                 size: 30.0,
                               )
                             ),
                             onTap: () {
                               MyRouter.pushNoParams(context,MyRouter.userPage);
                             },
                           )
                         ],
                      ),
                      alignment: Alignment(0.0, 0.0),
                    ),
                  ),
                  // The "forceElevated" property causes the SliverAppBar to show
                  // a shadow. The "innerBoxIsScrolled" parameter is true when the
                  // inner scroll view is scrolled beyond its "zero" point, i.e.
                  // when it appears to be scrolled below the SliverAppBar.
                  // Without this, there are cases where the shadow would appear
                  // or not appear inappropriately, because the SliverAppBar is
                  // not actually aware of the precise position of the inner
                  // scroll views.
                  bottomTextString: titleList,
                  bottom: TabBar(
                    // These are the widgets to put in each tab in the tab bar.
                    tabs: titleList
                        .map((String name) => Container(
                      child: Text(
                        name,
                      ),
                      padding: const EdgeInsets.only(top: 2.0, bottom: 5.0),
                    ))
                        .toList(),
                  ),
                ),
              ),
            ];
          },
          //body表示具体展示的内容
          body:TabBarView(children: [News(url: 'http://www.appshuo.club/api/client/api/recommend/all?lastkey='),SliverContainer(url: 'http://www.appshuo.club/api/client/api/apps/all?lastkey=')]) ,
        ),
      ),
    );
  }
}